//
//  FirstViewController.m
//  XDCommonApp
//
//  Created by XD-XY on 2/12/14.
//  Copyright (c) 2014 XD-XY. All rights reserved.
//

#import "FirstViewController.h"
#import "XDHeader.h"
#import "XDTools.h"

@interface FirstViewController ()

@end

@implementation FirstViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    self.leftBtn.hidden =YES;

    [self changeFrameWhenHiddenNavigationBar];
    
    [[XDTools sharedXDTools] checkVersion:self isShowAlert:YES];
    
    NSArray * arr = @[@"纯文本",@"菊花",@"菊花文本",@"成功",@"错误"];
    for (int i =0;i <5;i++){
        UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(100, 100+60*i, 100, 40);
        button.backgroundColor = [UIColor greenColor];
        [button setTitle:[arr objectAtIndex:i] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        button.tag = i+1;
        [self.contentView addSubview:button];
    }
}

-(void)btnClick:(UIButton *)sender
{
    DDLOG_CURRENT_METHOD;
    if (sender.tag==1){
        [XDTools showTips:@"操作成功" toView:self.contentView];
    }else if (sender.tag ==2){
        [XDTools showProgress:self.contentView];
    }else if (sender.tag ==3){
        [XDTools showProgress:self.contentView showText:@"正在加载..."];
    }else if (sender.tag ==4){
    
    }else if (sender.tag ==5){
    
    }
}

-(void)getData
{
    NSDictionary *dict = @{@"module":@"1",
                           @"page":@"1",
                           };
    
    __weak ASIHTTPRequest *request = [XDTools getRequestWithDict:dict API:API_GetInfoList];
    [request setCompletionBlock:^{
        NSString *responseString = [request responseString];
        NSMutableString *muString = [[NSMutableString alloc] initWithString:responseString];
        [muString replaceOccurrencesOfString:@"\r" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, muString.length)];
        [muString replaceOccurrencesOfString:@"\n" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, muString.length)];
        [muString replaceOccurrencesOfString:@"\t" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, muString.length)];
        NSDictionary *tempDic = [XDTools  JSonFromString:muString];
        
    }];
    
    [request setFailedBlock:^{
       
    }];
    [request startAsynchronous];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
